﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Resources;
using DevExpress.XtraBars.Localization;
using DevExpress.XtraReports.Localization;
using DevExpress.XtraPrinting.Localization;

namespace Client
{
    public class NativeResources
    {
        /// <summary>
        /// 汉化部分控件
        /// </summary>
        public static void ExeResource()
        {
            DevExpress.XtraGrid.Localization.GridLocalizer.Active = new GridLocalizationResEx();
            DevExpress.XtraBars.Localization.BarLocalizer.Active = new BarLocalizationResEx();
            DevExpress.XtraEditors.Controls.Localizer.Active = new EditorsLocalizationResEx();
            DevExpress.XtraTreeList.Localization.TreeListLocalizer.Active = new TreeListLocalizationResEx();
            DevExpress.XtraReports.Localization.ReportLocalizer.Active = new ReportLocalizationResEx();
            DevExpress.XtraPrinting.Localization.PreviewLocalizer.Active = new PreviewLocalizationResEx();
        }
    }

    internal class GridLocalizationResEx : DevExpress.XtraGrid.Localization.GridLocalizer
    {
        ResourceManager manager = null;
        public GridLocalizationResEx()
        {
            CreateResourceManager();
        }
        protected virtual void CreateResourceManager()
        {
            if (manager != null) manager.ReleaseAllResources();
            Assembly assembly = Assembly.LoadFile(System.Windows.Forms.Application.StartupPath + "\\Res\\DevExpress.XtraGrid.v9.3.resources.dll");
            this.manager = new System.Resources.ResourceManager("DevExpress.XtraGrid.LocalizationRes.zh-CN", assembly);
        }
        protected virtual ResourceManager Manager { get { return manager; } }
        public override string Language { get { return System.Globalization.CultureInfo.CurrentUICulture.Name; } }
        public override string GetLocalizedString(DevExpress.XtraGrid.Localization.GridStringId id)
        {
            string resStr = "GridStringId." + id.ToString();
            string ret = Manager.GetString(resStr);
            if (ret == null) ret = "";
            return ret;
        }
    }

    internal class EditorsLocalizationResEx : DevExpress.XtraEditors.Controls.EditResLocalizer
    {
        ResourceManager manager = null;
        public EditorsLocalizationResEx()
        {
            CreateResourceManager();
        }
        protected override void CreateResourceManager()
        {
            if (manager != null) manager.ReleaseAllResources();
            Assembly assembly = Assembly.LoadFile(System.Windows.Forms.Application.StartupPath + "\\Res\\DevExpress.XtraEditors.v9.3.resources.dll");
            this.manager = new System.Resources.ResourceManager("DevExpress.XtraEditors.LocalizationRes.zh-CN", assembly);
        }
        protected override ResourceManager Manager { get { return manager; } }
        public override string Language { get { return System.Globalization.CultureInfo.CurrentUICulture.Name; } }
        public override string GetLocalizedString(DevExpress.XtraEditors.Controls.StringId id)
        {
            string resStr = "StringId." + id.ToString();
            string ret = Manager.GetString(resStr);
            if (ret == null) ret = "";
            return ret;
        }
    }

    internal class TreeListLocalizationResEx : DevExpress.XtraTreeList.Localization.TreeListResLocalizer
    {
        ResourceManager manager = null;
        public TreeListLocalizationResEx()
        {
            CreateResourceManager();
        }
        protected override void CreateResourceManager()
        {
            if (manager != null) manager.ReleaseAllResources();
            Assembly assembly = Assembly.LoadFile(System.Windows.Forms.Application.StartupPath + "\\Res\\DevExpress.XtraTreeList.v9.3.resources.dll");
            this.manager = new System.Resources.ResourceManager("DevExpress.XtraTreeList.LocalizationRes.zh-CN", assembly);
        }
        protected override ResourceManager Manager { get { return manager; } }
        public override string Language { get { return System.Globalization.CultureInfo.CurrentUICulture.Name; } }
        public override string GetLocalizedString(DevExpress.XtraTreeList.Localization.TreeListStringId id)
        {
            string resStr = "TreeListStringId." + id.ToString();
            string ret = Manager.GetString(resStr);
            if (ret == null) ret = "";
            return ret;
        }
    }

    internal class BarLocalizationResEx : DevExpress.XtraBars.Localization.BarResLocalizer
    {
        ResourceManager manager = null;
        public BarLocalizationResEx()
        {
            CreateResourceManager();
        }
        protected override void CreateResourceManager()
        {
            if (manager != null) manager.ReleaseAllResources();
            Assembly assembly = Assembly.LoadFile(System.Windows.Forms.Application.StartupPath + "\\Res\\DevExpress.XtraBars.v9.3.resources.dll");
            string[] str = assembly.GetManifestResourceNames();
            this.manager = new System.Resources.ResourceManager("DevExpress.XtraBars.LocalizationRes.zh-CN", assembly);
        }
        protected override ResourceManager Manager { get { return manager; } }
        public override string Language { get { return System.Globalization.CultureInfo.CurrentUICulture.Name; } }
        public override string GetLocalizedString(DevExpress.XtraBars.Localization.BarString id)
        {
            string resStr = "BarStringId." + id.ToString();
            string ret = Manager.GetString(resStr);
            if (ret == null) ret = "";
            return ret;
        }
    }


    internal class ReportLocalizationResEx : DevExpress.XtraReports.Localization.ReportResLocalizer
    {
        ResourceManager manager = null;
        public ReportLocalizationResEx()
        {
            CreateResourceManager();
        }
        protected override void CreateResourceManager()
        {
            if (manager != null) manager.ReleaseAllResources();
            Assembly assembly = Assembly.LoadFile(System.Windows.Forms.Application.StartupPath + "\\Res\\DevExpress.XtraReports.v9.3.resources.dll");
            this.manager = new System.Resources.ResourceManager("DevExpress.XtraReports.LocalizationRes.zh-CN", assembly);
        }
        protected override ResourceManager Manager { get { return manager; } }
        public override string Language { get { return System.Globalization.CultureInfo.CurrentUICulture.Name; } }

        public override string GetLocalizedString(DevExpress.XtraReports.Localization.ReportStringId id)
        {
            string resStr = "ReportStringId." + id.ToString();
            string ret = Manager.GetString(resStr);
            if (ret == null) ret = "";
            return ret;
        }
    }

    /// <summary>
    /// 本地化打印预览窗体
    /// </summary>
    internal class PreviewLocalizationResEx : DevExpress.XtraPrinting.Localization.PreviewResLocalizer
    {
        ResourceManager manager = null;

        public PreviewLocalizationResEx()
        {
            CreateResourceManager();
        }

        protected override void CreateResourceManager()
        {
            if (manager != null) manager.ReleaseAllResources();

            Assembly assembly = Assembly.LoadFile(System.Windows.Forms.Application.StartupPath + "\\Res\\DevExpress.Utils.v9.3.resources.dll");
            this.manager = new System.Resources.ResourceManager("DevExpress.Utils.LocalizationRes.zh-CN", assembly);


        }

        protected override ResourceManager Manager
        {
            get
            {
                return manager;
            }
        }

        public override string Language
        {
            get
            {
                return System.Globalization.CultureInfo.CurrentUICulture.Name;
            }
        }

        public override string GetLocalizedString(PreviewStringId id)
        {
            string ret = "";
            switch (id)
            {
                case PreviewStringId.PreviewForm_Caption: return "报表预览";
                case PreviewStringId.MenuItem_File: return "文件";
                case PreviewStringId.MenuItem_PageSetup: return "页面设置";
                case PreviewStringId.MenuItem_PrintDirect: return "打印设置...";
                case PreviewStringId.MenuItem_Print: return "打印";
                case PreviewStringId.MenuItem_Export: return "导出";
                case PreviewStringId.MenuItem_PdfDocument: return "Pdf文档";
                case PreviewStringId.MenuItem_RtfDocument: return "Rtf文档";
                case PreviewStringId.MenuItem_TxtDocument: return "Txt文档";
                case PreviewStringId.MenuItem_XlsDocument: return "Xls文档";
                case PreviewStringId.MenuItem_HtmDocument: return "Htm文档";
                case PreviewStringId.MenuItem_GraphicDocument: return "Graphic文档";
                case PreviewStringId.MenuItem_CsvDocument: return "Csv文档";
                case PreviewStringId.MenuItem_MhtDocument: return "Mht文档";
                case PreviewStringId.MenuItem_Send: return "发送";
                case PreviewStringId.MenuItem_Exit: return "退出";

                case PreviewStringId.MenuItem_View: return "查看";
                case PreviewStringId.MenuItem_ViewToolbar: return "工具栏";
                case PreviewStringId.MenuItem_ViewStatusbar: return "状态条";
                case PreviewStringId.MenuItem_PageLayout: return "页面布局";

                case PreviewStringId.MenuItem_Background: return "背景";
                case PreviewStringId.MenuItem_BackgrColor: return "颜色";
                case PreviewStringId.MenuItem_Watermark: return "水印";

                case PreviewStringId.Msg_IncorrectPageRange: return "设置的页边距不正确";

                case PreviewStringId.TB_TTip_PageSetup: return "页面设置";
                case PreviewStringId.TB_TTip_Print: return "打印";
                case PreviewStringId.TB_TTip_Export: return "导出";
                case PreviewStringId.TB_TTip_Close: return "退出";
                case PreviewStringId.TB_TTip_Send: return "发送";
                default:
                    ret = "";
                    break;
            }

            return ret;
        }

    }
}
